class iJsBridge {

  constructor(options={}) {
    // this.alert = options.alert || window.alert;
  }

  /*这段代码是固定的，必须要放到js中*/
  setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) {
      return callback(WebViewJavascriptBridge);
    }
    if (window.WVJBCallbacks) {
      return window.WVJBCallbacks.push(callback);
    }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function () {
      document.documentElement.removeChild(WVJBIframe)
    }, 0)
  }
  //注册方法供IOS调用
  register() {
    /*我们在这注册一个js调用OC的方法，不带参数，且不用ObjC端反馈结果给JS：打开本demo对应的博文*/
    bridge.registerHandler('openWebviewBridgeArticle', function () {
      log("openWebviewBridgeArticle was called with by ObjC")
    })
    /*JS给ObjC提供公开的API，在ObjC端可以手动调用JS的这个API。接收ObjC传过来的参数，且可以回调ObjC*/
    bridge.registerHandler('getUserInfos', function (data, responseCallback) {
      log("Get user information from ObjC: ", data)
      responseCallback({
        'userId': '123456',
        'blog': '标哥的技术博客'
      })
    })
  }

  //调用IOS注册的方法
  call(method, params = {},callback="") {
    this.setupWebViewJavascriptBridge(function (bridge) {
      bridge.callHandler(method, params, function(response){
        callback(response);
      });
    })
  }

  //跳转到支付页面去支付

  // toAppPay(){
  //   call('toPayMethod',);
  // }





}
export default iJsBridge;
